package com.situ.mall.controller;


import com.situ.mall.constant.RedisConstants;
import com.situ.mall.pojo.Permission;
import com.situ.mall.pojo.query.PermissionQuery;
import com.situ.mall.service.IPermissionService;
import com.situ.mall.util.PageResult;
import com.situ.mall.util.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gao
 * @since 2025-06-26
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/update")
    public Result update(Permission permission) {
        permissionService.updateById(permission);
        return Result.ok("修改成功");
    }

    @RequestMapping("/selectById")
    public Result<Permission> selectById(Integer id) {
        Permission permission = permissionService.getById(id);
        return Result.ok(permission);
    }

    @RequestMapping("/add")
    public Result add(Permission permission) {
        permissionService.save(permission);
        return Result.ok("添加成功");
    }

    // /permission/list?page=1&limit=10
    // /permission/list?page=1&limit=10&name=zhangsan
    // /permission/list?page=1&limit=10&name=zhangsan&beginCreateDate
    @RequestMapping("/list")
    public PageResult list(PermissionQuery permissionQuery) {
        PageResult pageResult = permissionService.list(permissionQuery);
        return pageResult;
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        permissionService.removeById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(Integer[] ids) {
        System.out.println(Arrays.toString(ids));
        permissionService.removeBatchByIds(Arrays.asList(ids));
        return Result.ok("删除成功");
    }

}

